package com.emep.changzhi.analyse.service.error;

import com.emep.changzhi.analyse.entity.error.UnorganizedIndustry;
import com.emep.changzhi.analyse.repository.error.UnorganizedIndustryRepository;
import com.emep.changzhi.analyse.utils.MapUtils;
import com.emep.changzhi.analyse.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author xy
 * @Description: 工业无组织排放异常业务层
 * @date 2018/2/27 9:01
 * @version V1.0
 */
@Slf4j
@Service
public class UnorganizedIndustryService {
    @Resource
    private UnorganizedIndustryRepository unorganizedIndustryRepository;
    private static final Logger logger = LoggerFactory.getLogger(UnorganizedIndustryService.class);


    /**
     *
     * 新增工业无组织排放异常数据
     *
     * @param payload
     * @return
     * @throws Exception
     */
    public UnorganizedIndustry save(Map<String, Object> payload) {
        UnorganizedIndustry unorganizedIndustry = null;
        try {
            UnorganizedIndustry unorganizedIndustry1 = (UnorganizedIndustry) MapUtils.convertMap(UnorganizedIndustry.class,payload);
            unorganizedIndustry=unorganizedIndustryRepository.save(unorganizedIndustry1);
        } catch (IntrospectionException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        return unorganizedIndustry;
    }
    /**
     * @author xy
     * @Description: 首页
     * @date 2018/3/8 10:11
     * @version V1.0
     */
    public List<UnorganizedIndustry> findUnorganizedIndustryByHome(Integer pageSize){
        List<UnorganizedIndustry> unorganizedIndustrys = null;
        try {
            unorganizedIndustrys = unorganizedIndustryRepository.unorganizedIndustryHome(pageSize);
        }catch (Exception e){
            log.error(e.getClass().getName()+":"+ e.getMessage());
            log.error(e.getLocalizedMessage());
        }
        return unorganizedIndustrys;

    }
    /**
     * @author xy
     * @Description: 翻页查询
     * @date 2018/3/8 10:18
     * @version V1.0
     */

    public List<UnorganizedIndustry> findUnorganizedIndustryByFlip(String id,Integer pageSize) {
        List<UnorganizedIndustry> unorganizedIndustrys = null;
        try {
            unorganizedIndustrys = unorganizedIndustryRepository.unorganizedIndustryFlip(id,pageSize);
        }catch (Exception e){
            log.error(e.getClass().getName()+":"+ e.getMessage());
            log.error(e.getLocalizedMessage());
        }
        return unorganizedIndustrys;
    }

}
